import { useEffect, useState, useRef } from "react";
function useCallbackState(state: any) {
  const callbackRef = useRef<any>();
  const [data, setData] = useState(state);
  useEffect(() => {
    callbackRef.current && callbackRef.current(data);
  }, [data]);

  return [
    data,
    function (value: any, callback: undefined) {
      callbackRef.current = callback;
      setData(value);
    },
  ];
}
export { useCallbackState };
